package constant

import (
	"encoding/json"
	"errors"
	"net/http"
)

type CodeMessage struct {
	error
	Code       int    `json:"code"`
	Message    string `json:"msg"`
	statusCode int
}

func (c CodeMessage) StatusCode() int {
	return c.statusCode
}

func (c CodeMessage) Body() []byte {
	msg, _ := json.Marshal(c)
	return msg
}

func ModuleError(baseCode int) int {
	return Module*100000 + baseCode
}

var (
	Module        = 4000
	ActionSuccess = &CodeMessage{errors.New(""), 0, "ok.ActionSuccess", http.StatusOK}

	ErrorInfoFile = &CodeMessage{
		error:      errors.New("err.ErrorInfoFile"),
		Code:       ModuleError(00001),
		statusCode: http.StatusInternalServerError,
	}
	ErrorFileMove = &CodeMessage{
		error:      errors.New("err.ErrorFileMove"),
		Code:       ModuleError(00002),
		statusCode: http.StatusTooEarly,
	}
	ErrorMissingField = &CodeMessage{
		error:      errors.New("err.ErrorMissingField"),
		Code:       ModuleError(00003),
		statusCode: http.StatusBadRequest,
	}
	ErrorCreateDirectory = &CodeMessage{
		error:      errors.New("err.ErrorCreateDirectory"),
		Code:       ModuleError(00004),
		statusCode: http.StatusInternalServerError,
	}
	ErrorUpdateFileInfo = &CodeMessage{
		error:      errors.New("err.ErrorUpdateFileInfo"),
		Code:       ModuleError(00005),
		statusCode: http.StatusInternalServerError,
	}
)
